<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
$lotto_id = intval( $_GET['id'] );
$conf = new Config();
$stopbet = $conf->get( "stopbet" );
if ( !isset( $_SESSION['saystopmod'] ) )
{
    $_SESSION['saystopmod'] = 0;
}
$saystopmod = $_SESSION['saystopmod'];
if ( $stopbet <= date( "Hi" ) && !$saystopmod )
{
    $saystopmod = 1;
    $_SESSION['saystopmod'] = $saystopmod;
    echo "-1";
    exit();
}
if ( $curruser['acl'] == 300 )
{
    include_once( "centralize/centralize_class/config_cen.php" );
    include_once( "centralize/centralize_class/db_cen.php" );
    $cid = intval( getvar( "cid" ) );
    if ( !isset( $g_cen_info[$cid] ) )
    {
        exit();
    }
    $cen_Flag = 1;
}
else
{
    $cid = 0 - 1;
    $cen_Flag = 0;
}
$maxbet_hint = intval( $conf->get( "max_bat_hint" ) );
$member_max_limit = intval( $conf->get( "member_max_limit" ) );
$disk_code = "a";
$diskStr = "";
include( "class_6h/BetTotal_6h.php" );
$BetTotal_6h = new BetTotal_6h( $lotto_id, $cid );
$dataTotalArr = array();
$showDataArr = array();
$total_win = array();
$bettypeStr = "1001,1,2,3,13,14,18,20,28,30,47,49,50";
$betsGame = "1001";
$hint_mode = 0;
$chktimer = systime( ) - 28;
$split = 1;
$ratemod = 2;
$theacl = $curruser['acl'];
$userid = $curruser['id'];
$showid = $theacl == 255 ? "0" : $userid;
$dataTotalArr[$betsGame] = array( "bettype" => $betsGame, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0 );
$dataTotalArr[13] = array( "bettype" => 13, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0 );
$dataTotalArr[14] = array( "bettype" => 14, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0 );
$dataTotalArr[18] = array( "bettype" => 18, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0 );
$dataTotalArr[1] = array( "bettype" => 1, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0 );
$dataTotalArr[2] = array( "bettype" => 2, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0 );
$dataTotalArr[3] = array( "bettype" => 3, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0 );
$dataTotalArr[20] = array( "bettype" => 20, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0 );
$dataTotalArr[28] = array( "bettype" => 28, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0 );
$dataTotalArr[30] = array( "bettype" => 30, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0 );
//$dataTotalArr[46] = array( "bettype" => 46, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0 );
$dataTotalArr[47] = array( "bettype" => 47, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0 );
$dataTotalArr[49] = array( "bettype" => 49, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0 );
$dataTotalArr[50] = array( "bettype" => 50, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0 );
$totalRs = $BetTotal_6h->getDataListTotal( $lotto_id, $bettypeStr, $showid, $split, $diskStr );
while ( !$totalRs->eof )
{
    $tempIdx = $totalRs->f['bettype'];
    $dataTotalArr[$tempIdx] = $totalRs->f;
    $totalRs->next();
}
$totalRs->close();
$lostwin = array();
$winlost = $dataTotalArr[$betsGame]['amount'] - $dataTotalArr[$betsGame]['back1'] + $dataTotalArr[$betsGame]['back2'];
$i = 1;
while ( $i < 50 )
{
    $showDataArr[$betsGame][$i] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => $winlost, "namount" => "" );
    $lostwin[$betsGame][$i] = $winlost;
    ++$i;
}
$total_win[$betsGame] = 0;
$i = 1;
while ( $i <= 3 )
{
    $showDataArr[13][$i] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
    //$showDataArr[46][$i] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
    ++$i;
}
$total_win[13] = 0;
//$total_win[46] = 0;
$i = 1;
while ( $i < 13 )
{
    $showDataArr[14][$i] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
    $showDataArr[18][$i] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "" );
    ++$i;
}
$total_win[14] = 0;
$total_win[18] = 0;
$showDataArr[1][1] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
$showDataArr[1][2] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
$showDataArr[2][1] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
$showDataArr[2][2] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
$showDataArr[3][1] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
$showDataArr[3][2] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
$showDataArr[20][1] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
$showDataArr[20][2] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
$showDataArr[28][1] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
$showDataArr[28][2] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
$showDataArr[30][1] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
$showDataArr[30][2] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
$showDataArr[47][1] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
$showDataArr[47][2] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
for($i=0;$i<=4;$i++)
	$showDataArr[49][$i] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );
for($i=0;$i<=9;$i++)
	$showDataArr[50][$i] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "", "srd" => 0 );

$total_win[1] = 0;
$total_win[2] = 0;
$total_win[3] = 0;
$total_win[47] = 0;
$total_win[49] = 0;
$total_win[50] = 0;
$total_win[20] = 0;
$total_win[28] = 0;
$total_win[30] = 0;
$sql = $BetTotal_6h->getDataListByNumSsSQL( $lotto_id, $bettypeStr, $showid, $diskStr, $split, $ratemod );
if ( $cen_Flag )
{
    $rs = getdb_cen( $cid, $sql );
}
else
{
    $rs = getdb( $sql );
}
$updatetime = systime( ) - 30;
while ( !$rs->eof )
{
    $bettype = $rs->f['bettype'];
    $winlost = $dataTotalArr[$bettype]['amount'] - $rs->f['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$rs->f[1]]['back2'];
    $total_win[$bettype] = $dataTotalArr[$bettype]['amount'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$rs->f[1]]['back2'];
    $i = intval( $rs->f['numbers'] );
    $showDataArr[$bettype][$i]['totalnum'] = $rs->f['totalnum'];
    $showDataArr[$bettype][$i]['amount'] = $rs->f['amount'];
    $showDataArr[$bettype][$i]['amount_rate'] = $rs->f['amount_rate'];
    $showDataArr[$bettype][$i]['rate'] = $rs->f['rate'];
    if ( $bettype == $betsGame )
    {
        $lostwin[$bettype][$i] = $winlost;
    }
    if ( $rs->f['bettype'] == 1001 && 0 < $maxbet_hint && $maxbet_hint <= $rs->f['amount'] && $chktimer <= $rs->f['updatetime'] )
    {
        ++$hint_mode;
    }
    $rs->next();
}
$rs->close();
$split = 1;
$percent = 1;
if ( $cen_Flag )
{
    $rs = getdb_cen( $cid, "select * from rate0a where lotto_id={$lotto_id}" );
}
else
{
    $rs = getdb( "select * from rate0a where lotto_id={$lotto_id}" );
}
if ( $rs->eof )
{
    exit( "Error ID!" );
}
$i = 1;
while ( $i < 50 )
{
    $showDataArr[$betsGame][$i]['rate'] = $rs->f["r".d2( $i )] - 0;
    ++$i;
}
$rs->close();
if ( $cen_Flag )
{
    $rs = getdb_cen( $cid, "select * from rate1a where lotto_id={$lotto_id}" );
}
else
{
    $rs = getdb( "select * from rate1a where lotto_id={$lotto_id}" );
}
if ( $rs->eof )
{
    exit( "Error ID!" );
}
$showDataArr[1][1]['rate'] = $rs->f['r1_1'] - 0;
$showDataArr[1][2]['rate'] = $rs->f['r1_2'] - 0;
$showDataArr[2][1]['rate'] = $rs->f['r2_1'] - 0;
$showDataArr[2][2]['rate'] = $rs->f['r2_2'] - 0;
$showDataArr[3][1]['rate'] = $rs->f['r3_1'] - 0;
$showDataArr[3][2]['rate'] = $rs->f['r3_2'] - 0;
$showDataArr[13][1]['rate'] = $rs->f['r13_1'] - 0;
$showDataArr[13][2]['rate'] = $rs->f['r13_2'] - 0;
$showDataArr[13][3]['rate'] = $rs->f['r13_3'] - 0;
$i = 1;
while ( $i < 13 )
{
    $showDataArr[14][$i]['rate'] = $rs->f["r14_".$i] - 0;
    $showDataArr[18][$i]['rate'] = $rs->f["r18_".$i] - 0;
    ++$i;
}
$showDataArr[20][1]['rate'] = $rs->f['r20_1'] - 0;
$showDataArr[20][2]['rate'] = $rs->f['r20_2'] - 0;
$showDataArr[28][1]['rate'] = $rs->f['r28_1'] - 0;
$showDataArr[28][2]['rate'] = $rs->f['r28_2'] - 0;
$showDataArr[30][1]['rate'] = $rs->f['r30_1'] - 0;
$showDataArr[30][2]['rate'] = $rs->f['r30_2'] - 0;
//$showDataArr[46][1]['rate'] = $rs->f['r46_1'] - 0;
//$showDataArr[46][2]['rate'] = $rs->f['r46_2'] - 0;
//$showDataArr[46][3]['rate'] = $rs->f['r46_3'] - 0;
$showDataArr[47][1]['rate'] = $rs->f['r47_1'] - 0;
$showDataArr[47][2]['rate'] = $rs->f['r47_2'] - 0;
$rs->close();
$rs = getdb( "select * from rate37 where lotto_id={$lotto_id} and disk=1 order by bettype" );
if ( $rs->eof )
{
    exit( "Error ID!" );
}
while(!$rs->eof)
{
	if($rs->f["bettype"]==49)
	{
		for($i=0;$i<=4;$i++)
			$showDataArr[49][$i]['rate']=$rs->f['r'.$i];		
	}
	else
	{
		for($i=0;$i<=9;$i++)
			$showDataArr[50][$i]['rate']=$rs->f['r'.$i];	
	}
	$rs->movenext();	
}
$rs->close();
if ( isset( $showDataArr[$betsGame] ) && intval( $dataTotalArr[$betsGame]['amount'] ) != 0 )
{
    asort( $lostwin[$betsGame] );
    reset( $lostwin[$betsGame] );
    $k = 1;
    $showDataArrTemp = array();
    foreach ( $lostwin[$betsGame] as $key => $val )
    {
        $showDataArrTemp[$betsGame][$k] = $showDataArr[$betsGame][$key];
        ++$k;
    }
    $showDataArr[$betsGame] = $showDataArrTemp[$betsGame];
}
$onlinesum = 0;
sess_gc();
if ( $cen_Flag )
{
    $rs = getdb_cen( $cid, "select count(sid) from k_sessions where uid!=2" );
}
else
{
    $rs = getdb( "select count(sid) from k_sessions where uid!=2" );
}
if ( !$rs->eof )
{
    $onlinesum = $rs->f[0];
}
$rs->close();
if ( $member_max_limit < $onlinesum )
{
    $conf->set( "member_max_limit", $onlinesum );
}
echo $onlinesum."@".$total_win[$betsGame]."@".$hint_mode;
$i = 1;
while ( $i < 50 )
{
    echo ",".$showDataArr[$betsGame][$i]['numbers']."@".$showDataArr[$betsGame][$i]['rate']."@".$showDataArr[$betsGame][$i]['totalnum']."@".$showDataArr[$betsGame][$i]['amount'];
    echo "@".$showDataArr[$betsGame][$i]['amount_rate'];
    ++$i;
}
echo "\n";
echo $total_win[1];
$i = 1;
while ( $i < 3 )
{
    echo ",".$showDataArr[1][$i]['rate']."@".$showDataArr[1][$i]['totalnum']."@".$showDataArr[1][$i]['amount'];
    echo "@".$showDataArr[1][$i]['amount_rate'];
    ++$i;
}
echo "\n";
echo $total_win[2];
$i = 1;
while ( $i < 3 )
{
    echo ",".$showDataArr[2][$i]['rate']."@".$showDataArr[2][$i]['totalnum']."@".$showDataArr[2][$i]['amount'];
    echo "@".$showDataArr[2][$i]['amount_rate'];
    ++$i;
}
echo "\n";
echo $total_win[3];
$i = 1;
while ( $i < 3 )
{
    echo ",".$showDataArr[3][$i]['rate']."@".$showDataArr[3][$i]['totalnum']."@".$showDataArr[3][$i]['amount'];
    echo "@".$showDataArr[3][$i]['amount_rate'];
    ++$i;
}
echo "\n";
echo $total_win[13];
$i = 1;
while ( $i < 4 )
{
    echo ",".$showDataArr[13][$i]['rate']."@".$showDataArr[13][$i]['totalnum']."@".$showDataArr[13][$i]['amount'];
    echo "@".$showDataArr[13][$i]['amount_rate'];
    ++$i;
}
echo "\n";
echo $total_win[14];
$i = 1;
while ( $i < 13 )
{
    echo ",".$showDataArr[14][$i]['rate']."@".$showDataArr[14][$i]['totalnum']."@".$showDataArr[14][$i]['amount'];
    echo "@".$showDataArr[14][$i]['amount_rate'];
    ++$i;
}
echo "\n";
echo $total_win[18];
$i = 1;
while ( $i < 13 )
{
    echo ",".$showDataArr[18][$i]['rate']."@".$showDataArr[18][$i]['totalnum']."@".$showDataArr[18][$i]['amount'];
    echo "@".$showDataArr[18][$i]['amount_rate'];
    ++$i;
}
echo "\n";
echo $total_win[20];
$i = 1;
while ( $i < 3 )
{
    echo ",".$showDataArr[20][$i]['rate']."@".$showDataArr[20][$i]['totalnum']."@".$showDataArr[20][$i]['amount'];
    echo "@".$showDataArr[20][$i]['amount_rate'];
    ++$i;
}
echo "\n";
echo $total_win[28];
$i = 1;
while ( $i < 3 )
{
    echo ",".$showDataArr[28][$i]['rate']."@".$showDataArr[28][$i]['totalnum']."@".$showDataArr[28][$i]['amount'];
    echo "@".$showDataArr[28][$i]['amount_rate'];
    ++$i;
}
echo "\n";
echo $total_win[30];
$i = 1;
while ( $i < 3 )
{
    echo ",".$showDataArr[30][$i]['rate']."@".$showDataArr[30][$i]['totalnum']."@".$showDataArr[30][$i]['amount'];
    echo "@".$showDataArr[30][$i]['amount_rate'];
    ++$i;
}
echo "\n";
echo $total_win[47];
$i = 1;
while ( $i < 3 )
{
    echo ",".$showDataArr[47][$i]['rate']."@".$showDataArr[47][$i]['totalnum']."@".$showDataArr[47][$i]['amount'];
    echo "@".$showDataArr[47][$i]['amount_rate'];
    ++$i;
}
echo "\n";
echo $total_win[49];
for($i=0;$i<=4;$i++)
{
    echo ",".$showDataArr[49][$i]['rate']."@".$showDataArr[49][$i]['totalnum']."@".$showDataArr[49][$i]['amount'];
    echo "@".$showDataArr[49][$i]['amount_rate'];
}
echo "\n";
echo $total_win[50];
for($i=0;$i<=9;$i++)
{
    echo ",".$showDataArr[50][$i]['rate']."@".$showDataArr[50][$i]['totalnum']."@".$showDataArr[50][$i]['amount'];
    echo "@".$showDataArr[50][$i]['amount_rate'];
}
echo "\n";
include( "class_6h/class.menu.php" );
$fieldArr = array( "lotto_id" => $lotto_id, "split_id" => 1 );
$onlineMenu = new menu_6h( 1, $fieldArr );
echo $onlineMenu->getMenuAmu();
echo "\n";
exit();
?>